<!-- 呈送领导 主办 协办 -->
<template>
  <van-action-sheet v-model="showModel" :close-on-click-overlay="false" @closed="closeSheet"  :title="title">
    <view v-if="type == '1'">
      <van-grid :column-num="3" :border="false" :center="false" >
        <van-grid-item>
          <van-checkbox v-model="checkedAll" shape="square" @change="checkAll"
                        icon-size="36rpx">
            全选
          </van-checkbox>
        </van-grid-item>
        <van-checkbox-group v-model="cxResult" direction="horizontal" ref="csld">
          <van-grid-item v-for="(item,index) in forwardData.cxList">
            <van-checkbox  :name="item.userId + '_' + item.userName"
                           icon-size="34rpx" :key="item.userId"
                           :disabled='cxIds.filter(t => t == item.userId).length > 0'>
              {{item.userName}}
            </van-checkbox>
          </van-grid-item>
        </van-checkbox-group>
      </van-grid>
      <van-checkbox-group v-model="dsResult">
        <van-cell-group>
          <van-cell
              v-for="(item, index) in dsList"
              clickable
              :key="item"
              :title="`领导秘书代收`"
              @click="toggle(index)"
          >
            <template #right-icon>
              <van-checkbox :name="item" ref="checkboxes" />
            </template>
          </van-cell>
        </van-cell-group>
      </van-checkbox-group>
    </view>
    <view v-if="type == '2'">
      <van-grid :column-num="3" :border="false" :center="false" >
        <van-radio-group v-model="zbResult" direction="horizontal" >
          <van-grid-item v-for="(item,index) in zbList">
            <van-radio  :name="item.deptId + '_' + item.deptName + '_' + item.userId" icon-size="34rpx" :key="item.deptId">
              {{item.deptName}}
            </van-radio>
          </van-grid-item>
        </van-radio-group>
      </van-grid>
    </view>
    <view v-if="type == '3'">
      <van-grid :column-num="3" :border="false" :center="false" >
        <van-checkbox-group v-model="xbResult" direction="horizontal" >
          <van-grid-item v-for="(item,index) in forwardData.xbList">
            <van-checkbox  :name="item.deptId + '_' + item.deptName + '_' + item.userId"
                           icon-size="34rpx" :key="item.deptId"
                           :disabled='(xbIds.filter(t => t == item.userId).length > 0) || (forwardData.directDeptIds == item.deptId)'>
              {{item.deptName}}
            </van-checkbox>
          </van-grid-item>
        </van-checkbox-group>
      </van-grid>
    </view>
    <view class="padding-top-lg padding-bottom-lg">
      <van-row type="flex" justify="space-around">
        <van-col span="10">
          <van-button type="info" round plain hairline block @click="closeSheet">取消</van-button>
        </van-col>
        <van-col span="10">
          <van-button type="info" round block @click="toSave">确定</van-button>
        </van-col>
      </van-row>
    </view>
  </van-action-sheet>
</template>

<script>

export default{
  props: {
    showForward:{
      type: Boolean,
      default: false
    },
    //类型 1呈送 2主办 3协办
    tagType:{
      type: Number,
      default:1
    },
    forwardData: {
      type: Object
    }
  },

  data(){
    return{
      showModel: false,
      checkedAll: false, // 是否全选
      title: '',    // 标题
      type: '',     // 类型
      csList: [],   // 呈送领导集合
      zbList: [],   // 主办部门集合
      xbList: [],   // 协办部门集合
      cxIds: [],    // 已分送呈送领导id
      cxResult: [], // 选中的呈送领导id
      xbIds: [],    // 已分送协办部门id
      xbResult: [], // 选中的协办部门id
      zbResult: '', // 选中的主办部门id
      dsList: ['1'],
      dsResult: ['1'], // 是否领导秘书代收
    };
  },

  watch: {
    showForward(val) {
      this.showModel = val
    },
    tagType: {
      handler(nval, oval) {
        this.type = nval
        if(nval == '1') {
          this.title = '呈送领导'
        } else if(nval == '2') {
          this.title = '主办部门'
        } else if(nval == '3') {
          this.title = '分送部门'
        }
      },
      immediate: true,
      deep: true
    },
    // forwardData: {
    // 	handler(nval, oval){
    //     console.log("jianting fslist"+JSON.stringify(nval.xbList))
    // 		if(nval != null && nval.cxList != null) {
    // 			this.cxList = nval.cxList
    // 		}
    // 		if(nval != null && nval.praiseUserIds != null) {
    // 			this.cxIds = nval.praiseUserIds.split(',')
    // 		}
    // 		if(nval != null && nval.zbList != null) {
    // 			this.zbList = nval.zbList
    // 		}
    // 		if(nval != null && nval.directDeptIds != null) {
    // 			this.zbResult = nval.directDeptIds
    // 		}
    // 		if(nval != null && nval.xbList != null) {
    // 			this.xbList = nval.xbList
    // 		}
    // 		if(nval != null && nval.copyToUserIds != null) {
    // 			this.xbIds = nval.copyToUserIds.split(',')
    // 		}
    // 	},
    // 	immediate: true,
    // 	deep: true
    // }
  },

  mounted() {

  },

  methods: {

    // 呈送领导全选
    checkAll() {
      if (this.checkedAll) {
        this.$refs.csld.toggleAll(true);
      } else {
        this.$refs.csld.toggleAll();
      }
    },
    // 是否局长办公室代收
    toggle(index) {
      this.$refs.checkboxes[index].toggle();
    },
    // 关闭sheet
    closeSheet() {
      this.$emit('closeSheet', this.type)
    },
    // 保存sheet
    toSave() {
      let data = {}
      data.type = this.type
      if(this.type == "1" ){
        data.result = this.cxResult
        let ds = this.dsResult.toString()
        ds = (ds == null || ds == '') ? '0' : ds
        if(this.util.isEmpty(this.cxResult)) {
          this.$toast('请选择呈送领导')
          return false
        }
        data.dsResult = ds
      }else if(this.type == "2"){
        data.result = this.zbResult
      }else if(this.type == "3"){
        data.result = this.xbResult
      }
      this.$emit('saveSheet', data)
    }
  }
}
</script>

<style>
.van-action-sheet{
  z-index: 9999;
  min-height: 80%;
}
.search-add{
  position: fixed;
  height: 120rpx;
  width: 100%;
  z-index: 90;
}
.content{
  margin: 120rpx 0;
}
.bottom-btn{
  background-color: #FFFFFF;
  padding: 15rpx 0;
  position: fixed;
  width: 100%;
  height: 120rpx;
  bottom: 0;
  z-index: 999;
}
.popup-box{
  display: block;
  width: 100%;
  height: auto;
  padding:100rpx 0 20rpx;
}
/deep/ .van-cell__title {
  min-width: 20% !important;
}
</style>
